export class UiManager {
    constructor() {
        this.elements = {
            apiKeyInput: document.getElementById("apiKey"),
            toggleButton: document.getElementById("toggleVisibility"),
            iconSwitch: document.getElementById("iconSwitch"),
            languageSelect: document.getElementById("language"),
            modelSelect: document.getElementById("model"),
            selectionEnabled: document.getElementById("selectionEnabled"),
            rememberWindowSize: document.getElementById("rememberWindowSize"),
            pinWindow: document.getElementById("pinWindow"),
            balanceToggle: document.getElementById("balanceToggle"),
            balanceIcon: document.getElementById("balanceIcon"),
            balanceContent: document.getElementById("balanceContent"),
            totalBalance: document.getElementById("totalBalance")
        }, this.isBalanceVisible = !1
    }
    showMessage(e, t) {
        const n = document.querySelector(".input-container");
        if (!n) return;
        const s = document.querySelector(".error-message, .success-message");
        s && s.remove();
        const i = document.createElement("div");
        i.className = t ? "success-message" : "error-message", i.innerHTML = e, n.insertBefore(i, n.firstChild), e.includes("loading") || setTimeout((() => {
            i.remove()
        }), 2e3)
    }
    showLoadingState() {
        this.elements.totalBalance.innerHTML = '<span class="loading"></span>'
    }
    updateBalanceDisplay(e, t) {
        if (!e.is_available) return void(this.elements.totalBalance.textContent = t);
        const n = e.balance_infos[0];
        this.elements.totalBalance.textContent = new Intl.NumberFormat("zh-CN", {
            style: "currency",
            currency: n.currency || "CNY",
            minimumFractionDigits: 2
        }).format(n.total_balance)
    }
    toggleBalance() {
        return this.isBalanceVisible = !this.isBalanceVisible, this.elements.balanceContent.classList.toggle("show"), this.elements.balanceIcon.src = this.isBalanceVisible ? "../icons/show.svg" : "../icons/hiddle.svg", this.isBalanceVisible
    }
    toggleApiKeyVisibility() {
        const e = "password" === this.elements.apiKeyInput.type;
        this.elements.apiKeyInput.type = e ? "text" : "password", this.elements.iconSwitch.src = e ? "../icons/hiddle.svg" : "../icons/show.svg"
    }
    getApiKeyValue() {
        return this.elements.apiKeyInput.value.trim()
    }
    setApiKeyValue(e) {
        this.elements.apiKeyInput.value = e
    }
}